package com.kcwl.carrier.infrastructure.repository.persostence;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kcwl.carrier.domain.entity.CarrierBlacklist;
import com.kcwl.carrier.domain.repository.ICarrierBlacklistRepository;
import com.kcwl.carrier.domain.condition.CarrierBlacklistPageCondition;
import com.kcwl.carrier.infrastructure.repository.mapper.CarrierBlacklistMapper;
import com.kcwl.carrier.infrastructure.repository.po.CarrierBlacklistPO;
import com.kcwl.ddd.domain.entity.KcPage;
import com.kcwl.ddd.domain.repository.BaseRepositoryImpl;
import com.kcwl.framework.utils.KcBeanConverter;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author 刘旭超
 * @date 2022年11月21日 17:08
 * @Description
 */
@Component
public class CarrierBlacklistRepositoryImpl extends BaseRepositoryImpl<CarrierBlacklistMapper, CarrierBlacklistPO> implements ICarrierBlacklistRepository {

    @Resource
    private CarrierBlacklistMapper carrierBlacklistMapper;

    @Override
    public KcPage<CarrierBlacklist> queryPageList(CarrierBlacklistPageCondition condition) {
        IPage<CarrierBlacklistPO> iPage = carrierBlacklistMapper.queryPageList(new Page<>(condition.getCurPagerNo(), condition.getPageSize()), condition);
        return new KcPage<>(iPage.getTotal(), iPage.getCurrent(), iPage.getSize(), KcBeanConverter.toList(iPage.getRecords(), CarrierBlacklist.class));
    }

    /**
     * 添加黑名单
     */
    @Override
    public void addBlacklist(CarrierBlacklist command) {
        carrierBlacklistMapper.insert(KcBeanConverter.toBean(command, CarrierBlacklistPO.class));
    }

    @Override
    public Class<CarrierBlacklistPO> getPoClass() {
        return CarrierBlacklistPO.class;
    }
}
